// pages/evaluatedImmediatel/index.js
import {
  ApiOrderComment
} from '../../api/index'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    autosize: {
      maxHeight: 150,
      minHeight: 100
      
    },
    $path: app.globalData.$path,
    show: false,
    opt: {},
    rateData: [{
      id: 0,
      label: '超有耐心',
      check: false
    }, {
      id: 1,
      label: '医术高明',
      check: false
    }, {
      id: 2,
      label: '解答全面',
      check: false
    }, {
      id: 3,
      label: '体贴细心',
      check: false
    }, {
      id: 4,
      label: '对症下药',
      check: false
    }, {
      id: 5,
      label: '检查彻底',
      check: false
    }, {
      id: 6,
      label: '热情亲切',
      check: false
    }, {
      id: 7,
      label: '仁心仁德',
      check: false
    }, {
      id: 8,
      label: '帮助很大',
      check: false
    }],
    imageArr: []
  },

  onChange(event) {
    let name = event.currentTarget.dataset.v
    this.setData({
      [`opt.${name}`]: event.detail,
    });
  },

  onClickRate(e) {
    let id = e.currentTarget.dataset.v.id
    this.data.rateData[id].check = !this.data.rateData[id].check
    this.setData({
      rateData: this.data.rateData
    })
  },



  /* 点击图片 */
  imageClick() {
    this.setData({
      show: true
    })
  },
  getImageData(e) {
    this.data.imageArr.push(e.detail.value)
    this.setData({
      imageArr: this.data.imageArr
    })
  },


  submiteDataForm() {
    let val = []
    this.data.rateData.forEach(item => {
      if (item.check) {
        val.push(item.label)
      }
    })
    let query = {
      ...this.data.opt,
      pic: this.data.imageArr.toString(),
      label: val.toString()
    }
    ApiOrderComment(query).then(res => {
      if (res.code == '200') {
        wx.showToast({
          title: "提交成功",
        })
        setTimeout(() => {
          let pages = getCurrentPages();
          let prevPage = pages[pages.length - 2];
          prevPage.setData({
            comment: res.data
          })
          wx.navigateBack({
            delta: 1,
          })
        }, 1000);
      }
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      'opt.doctor_id': options.doctor_id,
      'opt.order_id': options.order_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})